import {express} from "../node-test";
import log from "./logger";
import weighter from "./weight";
import controller from "./controller";
import state from "./states/state";
import player from "./player";

const app = express()

class Webserver {
    init() {
        app.use(express.static('public'))

        app.get('/info', (req, res) => {
            res.send({
                active: [controller.R1, controller.R2, controller.R3, controller.R4],
                weight: weighter.weight,
                wen: weighter.wen,
                state: state.stateContext.name,
                msg: player.lastMsg,
                carNum: state.getVehicleNumber(),
                warehouse: state.warehouse,
                location: state.location,
                senderName: state.senderName,
                customerName: state.customerName,
            })
        })

        app.listen(9999, () => log.info('web server listening on port 9999'))
    }
}

const webserver = new Webserver();

export default webserver;